package main

import (
	"fmt"
	"csbuf"
	"csbuf/test"
	"time"
)

func isEqual(a interface{}, b interface{}) {
	if a != b {
		fmt.Println("no equal", a, b)
	}
}

func main() {
	fmt.Println("test")
	start := time.Now()
	for i:=0; i<1; i++ {
		parser := new(csbuf.CsbufParser)

		var a uint8 = 2
		var b uint16 = 6000
		var c uint32 = 123465789
		var d uint64 = 123456789123
		var e float32 = 1.11
		var f string = "hehe"

		var aa int8 = -2
		var bb int16 = -6000
		var cc int32 = -123456789
		var dd int64 = -12345678912

		var g bool = true
		var h float64 = 1.123

		parser.SetUint8(a, 1);
		parser.SetUint16(b, 2);
		parser.SetUint32(c, 3);
		parser.SetUint64(d, 4);
		parser.SetFloat(e, 5);
		//parser.SetString([]byte(f), 6);
		parser.SetString(f, 6);
		parser.SetInt8(aa, 7);
		parser.SetInt16(bb, 8);
		parser.SetInt32(cc, 9);
		parser.SetInt64(dd, 10);
		parser.SetBool(g, 11);
		parser.SetDouble(h, 12);

		p2 := new(csbuf.CsbufParser)
		p2.SetData(parser.GetData())

		// fmt.Println(p2.GetUint8(1)  )
		// fmt.Println(p2.GetUint16(2) )
		// fmt.Println(p2.GetUint32(3) )
		// fmt.Println(p2.GetUint64(4) )
		// fmt.Println(p2.GetFloat(5)  )
		// fmt.Println(p2.GetString(6) )
		// fmt.Println(p2.GetInt8(7)   )
		// fmt.Println(p2.GetInt16(8)  )
		// fmt.Println(p2.GetInt32(9)  )
		// fmt.Println(p2.GetInt64(10) )
		// fmt.Println(p2.GetBool(11)  )
		// fmt.Println(p2.GetDouble(12))
		isEqual(a,  p2.GetUint8(1)  )
		isEqual(b,  p2.GetUint16(2) )
		isEqual(c,  p2.GetUint32(3) )
		isEqual(d,  p2.GetUint64(4) )
		isEqual(e,  p2.GetFloat(5)  )
		isEqual(f,  p2.GetString(6) )
		isEqual(aa, p2.GetInt8(7)   )
		isEqual(bb, p2.GetInt16(8)  )
		isEqual(cc, p2.GetInt32(9)  )
		isEqual(dd, p2.GetInt64(10) )
		isEqual(g,  p2.GetBool(11)  )
		isEqual(h,  p2.GetDouble(12))

		t1 := new(test.Test1)
		t1.A_t1 = 1
		t1.At_2 = 2
		t1.At3_ = "ttttt"
		//t1.T4 = make([]uint32, 0, 2)
		t1.T4 = append(t1.T4, 1)
		t1.T4 = append(t1.T4, 2)
		t1.T4 = append(t1.T4, 10)

		t1.T5 = append(t1.T5, "go ")
		t1.T5 = append(t1.T5, "test")

		t1.T6.A = 100
		t1.T6.B = "link test"

		t1.T7 = append(t1.T7, test.Head{2, "m1"})
		t1.T7 = append(t1.T7, test.Head{4, "m2"})

		parser.Clear()
		t1.Marshal(parser)

		t2 := new(test.Test2)
		t2.Unmarshal(parser)
		isEqual(t1.A_t1,  t2.A_t1)
		isEqual(t1.At_2,  t2.At_2)
		isEqual(t1.At3_,  t2.At3_)

		// isEqual(t1.T4[0],  t2.T4[0])
		// isEqual(t1.T4[1],  t2.T4[1])
		// isEqual(t1.T4[2],  t2.T4[2])
		// isEqual(t1.T5[0],  t2.T5[0])
		// isEqual(t1.T5[1],  t2.T5[1])
		isEqual(t1.T6.A,  t2.T6.A)
		isEqual(t1.T6.B,  t2.T6.B)
		isEqual(t1.T6,  t2.T6)
		isEqual(t1.T7[0],  t2.T7[0])
		isEqual(t1.T7[1],  t2.T7[1])
	}
	fmt.Println(time.Now().Sub(start))
}